package com.info.zhiduoduo.repository.mapper.system;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.system.QuseryTradecategoryOneDto;
import com.info.zhiduoduo.repository.dto.system.QuseryTradecategoryTwoDto;
import com.info.zhiduoduo.repository.entity.system.SystemTradeCategory;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author TerryJ
 * @since 2018-12-08
 */
public interface TradeCategoryMapper extends BaseMapper<SystemTradeCategory> {

    @Select("select * from zdd_system_tradecategory")
    List<SystemTradeCategory> queryTradeCategory();

    /**
     * 查看一级的
     * @return
     */
    @Select("select tradecategoryid,tradecategory from zdd_system_tradecategory\n" +
            "where parentid = 0")
    List<QuseryTradecategoryOneDto> queryTradecategoryOne();

    /**
     * 查看二级的
     * @param parentid
     * @return
     */
    @Select(" select zst2.*,zst1.tradecategory as tradecategoryOne " +
            " from zdd_system_tradecategory zst2 " +
            " left join zdd_system_tradecategory zst1 on zst2.parentid = zst1.tradecategoryid " +
            " where IF(#{parentid}=0,zst2.parentid>0,zst2.parentid = #{parentid}) " +
            " order by sort")
    List<QuseryTradecategoryTwoDto> queryTradecategoryTwo(@Param("parentid") int parentid);
}
